extends IEventActuator


class_name RangeSetter
"""
用于修改RangeComponent数据的组件
"""


## Range属性名称
@export var range_name: String = ""
## 操作逻辑
@export var method: RangeAttribute.Method = RangeAttribute.Method.None
## 操作值
@export var value: int = 0
## 需要查找CharacterComponent的finder对象
@export var finder_or_character: Node = null


func __check_exports() -> Dictionary:
    return IComponent.merge({
        "method": func(): return method != RangeAttribute.Method.None,
        "finder_or_character": IComponent.find_child.bind(self, func(x): return x is INodeFinder, finder_or_character),
    }, super.__check_exports())

func get_wrapper() -> Node:
    return finder_or_character.find() if finder_or_character is INodeFinder else finder_or_character

func execute() -> void:
    var character: ICharacterComponent = get_wrapper()
    if not character:
        return
    var attr: RangeAttribute = character.get_attribute(range_name)
    if not attr:
        return
    attr.execute(method, value)
